<script>
export default {
  globalData: {
    user: {
      userId: '',
      phone: '',
      name: '',
      avatar: '',
      brief: '',
      cover: '',
      lastLoginAt: ''
    }
  },
  onLaunch() {
    console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
    uni.$on('getUserByApp', () => {
      this.getUserInfo()
    })
  },
  onShow() {
    this.getUserInfo()
  },
  onHide() {
  },
  onPageNotFound: () => {
    // 错误页面跳转首页
    uni.switchTab({
      url: '/pages/index/index'
    })
  },
  methods: {
    getUserInfo() {
      // 检测若没有登录，则跳转登录页
      const user = uni.getStorageSync('user_key')
      if (user) {
        this.globalData.user = user
      } else {
        uni.reLaunch({
          url: '/pages/login/login'
        })
      }
    }
  }
}
</script>

<style lang="scss">
@import '@/uni_modules/uni-scss/index.scss';
@import '@/tailwind.scss';
// 设置整个项目的背景色
</style>
